package com.dimong.www.loan.ui.adapter.main;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.dimong.loan.sdk.ui.adapter.BaseRecyclerAdapter;
import com.dimong.www.loan.bean.MainBean;
import com.dimong.www.loan.ui.adapter.holder.CarouselPicHolder;
import com.dimong.www.loan.ui.adapter.holder.CheckHeadHolder;
import com.dimong.www.loan.ui.adapter.holder.CheckHolder;
import com.dimong.www.loan.ui.adapter.holder.CreditCardHolder;
import com.dimong.www.loan.ui.adapter.holder.DefaultHolder;
import com.dimong.www.loan.ui.adapter.holder.LoadHotRecommendHeadHolder;
import com.dimong.www.loan.ui.adapter.holder.LoadHotRecommendHolder;
import com.dimong.www.loan.ui.adapter.holder.LoadRecommendHolder;
import com.dimong.www.loan.ui.adapter.holder.LoadStrategyHolder;

/**
 * Created by wuligang on 2018/3/28.
 */

public class MainAdapter extends BaseRecyclerAdapter<Object> {
    /**
     * 信用卡
     */
    public static int ITEM_CREDIT_CARD = 1;
    /**
     * 推荐分类
     */
    public static int ITEM_LOAD_RECOMMEND = 2;
    /**
     * 热门推荐的头
     */
    public static int ITEM_HOT_RECOMMEND_HEAD = 3;
    /**
     * 热门推荐
     */
    public static int ITEM_HOT_RECOMMEND = 4;
    /**
     * 顶部轮播图
     */
    public static int ITEM_CAROUSEL_PIC = 5;
    public static int ITEM_LOAD_EMPTY = 6;
    /**
     * 攻略
     */
    public static int ITEM_LOAN_STRATEGY = 7;
    public static int ITEM_CHECK = 8;
    public static int ITEM_CHECK_HEAD = 9;

    private LoadRecommendHolder.LoadRecommendHolderInterface loadRecommendHolderInterface;
    private CarouselPicHolder.CarouselPicHolderInterface carouselPicHolderInterface;

    public void setLoadRecommendHolderInterface(LoadRecommendHolder.LoadRecommendHolderInterface loadRecommendHolderInterface) {
        this.loadRecommendHolderInterface = loadRecommendHolderInterface;
    }

    public void setCarouselPicHolderInterface(CarouselPicHolder.CarouselPicHolderInterface carouselPicHolderInterface) {
        this.carouselPicHolderInterface = carouselPicHolderInterface;
    }

    @Override
    public RecyclerView.ViewHolder viewHolderCreate(ViewGroup parent, int viewType) {
        if (viewType == ITEM_CREDIT_CARD) {
            return new CreditCardHolder(parent.getContext(), parent);
        } else if (viewType == ITEM_LOAD_RECOMMEND) {
            return new LoadRecommendHolder(parent.getContext(), parent, loadRecommendHolderInterface);
        } else if (viewType == ITEM_HOT_RECOMMEND_HEAD) {
            return new LoadHotRecommendHeadHolder(parent.getContext(), parent);
        } else if (viewType == ITEM_HOT_RECOMMEND) {
            return new LoadHotRecommendHolder(parent.getContext(), parent);
        } else if (viewType == ITEM_CAROUSEL_PIC) {
            return new CarouselPicHolder(parent.getContext(), parent, carouselPicHolderInterface);
        } else if (viewType == ITEM_LOAN_STRATEGY) {
            return new LoadStrategyHolder(parent.getContext(), parent);
        } else if (viewType == ITEM_CHECK) {
            return new CheckHolder(parent.getContext(), parent);
        } else if (viewType == ITEM_CHECK_HEAD) {
            return new CheckHeadHolder(parent.getContext(), parent);
        }
        return new DefaultHolder(parent.getContext(), parent);
    }

    @Override
    public int getItemViewType(int position) {
        if (getItem(position) instanceof MainBean) {
            return ((MainBean) getItem(position)).getType();
        }
        return super.getItemViewType(position);
    }

    @Override
    public void viewHolderBind(RecyclerView.ViewHolder holder, int position) {
        MainBean mainBean = (MainBean) getItem(position);
        if (holder instanceof CarouselPicHolder) {
            CarouselPicHolder carouselPicHolder = (CarouselPicHolder) holder;
            carouselPicHolder.setData(mainBean.getObject());
        }
        if (holder instanceof LoadRecommendHolder) {
            LoadRecommendHolder loadRecommendHolder = (LoadRecommendHolder) holder;
            loadRecommendHolder.setData(mainBean.getObject());
        }
        if (holder instanceof LoadHotRecommendHolder) {
            LoadHotRecommendHolder loadHotRecommendHolder = (LoadHotRecommendHolder) holder;
            loadHotRecommendHolder.setData(mainBean.getObject());
        }
        if (holder instanceof CreditCardHolder) {
            CreditCardHolder creditCardHolder = (CreditCardHolder) holder;
            creditCardHolder.setData(mainBean.getObject());
        }
        if (holder instanceof CheckHolder) {
            ((CheckHolder) holder).setData(mainBean.getObject());
        }
        if (holder instanceof CheckHeadHolder) {
            ((CheckHeadHolder) holder).setData(mainBean.getObject());
        }
        if(holder instanceof  LoadStrategyHolder){
            ((LoadStrategyHolder) holder).setData(mainBean.getObject());
        }
    }

}
